
#include "stdafx.h"
#include "VirtualPosition.h"
#include "VARBinary.h"
#include "UserMessage.h"

CVirtualPosition::CVirtualPosition(bool bSimulate)
	: CDataPosition(bSimulate)
{
}

CVirtualPosition::~CVirtualPosition()
{
}

BOOL CVirtualPosition::OnInitDialog()
{
	CVirtualDlg::OnInitDialog();
	return TRUE;
}

intptr_t CVirtualPosition::getPositionStatus(CPoint &p)
{
	CMainPanelGetter main(this); if (!main.hasPanel()) return -2;
	intptr_t id = main.SendMainMessage(WM_Position_getPositionStatus); if (id < 0) return id;
	intptr_t result = main.SendMainMessage(WM_Position_getCtrlPointPos, id); if (result == -1) return -1;
	p.x = GET_X_LPARAM(result); p.y = GET_Y_LPARAM(result); return id;
}

void CVirtualPosition::setCtrlPointPos(intptr_t id, const CPoint &pFlash)
{
	CMainPanelGetter main(this); if (!main.hasPanel()) return;
	main.PostMainMessage(WM_Position_setCtrlPointPos, id, MAKELPARAM(pFlash.x, pFlash.y));
}

void CVirtualPosition::SetCtrlPoint(const CPoint *pOrignal, const CPoint *pPoint)
{
	CMainPanelGetter main(this); if (!main.hasPanel()) return;
	CVARBinary data;
	if (data.appendData(pOrignal, PROPPoint_COUNT*sizeof(CPoint), false) && data.appendData(pPoint, PROPPoint_COUNT*sizeof(CPoint), false))
		main.sendMainCopyData(0, CPDT_Position_SetCtrlPoint, data);
}

void CVirtualPosition::SetCtrlToolWin(const CPoint *pPoint)
{
	CMainPanelGetter main(this); if (!main.hasPanel()) return;
	main.sendMainCopyData(0, CPDT_Position_SetCtrlToolWin, (LPVOID)pPoint, PROPWindow_COUNT*sizeof(CPoint));
}

